/**
 * https://leetcode.cn/problems/kth-largest-element-in-a-stream/submissions/590066210/
 * 703.数据流中的第k大元素
 * easy 2024.12.29
 * 优先队列
 */

class KthLargest {
public:
    priority_queue<int,vector<int>,greater<int>> q;
    int n;
    KthLargest(int k, vector<int>& nums) {
        n=k;
        sort(nums.begin(),nums.end());
        for(int i=nums.size()-1;i>=0&&k--;i--)
            q.push(nums[i]);
    }
    
    int add(int val) {
        q.push(val);
        if(q.size()>n)
            q.pop();
        return q.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(val);
 */